package sl.com.sl;

import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.ImageIcon;
import javax.swing.JEditorPane;
import javax.swing.JLabel;

import main.MapScale;
import ar.com.visualAORE.view.ReqInternalFrame;

public class StripesImageContainer extends JLabel {
	JEditorPane edit;

	// public StripesImageContainer(BufferedImage img, JEditorPane editor, final
	// ReqInternalFrame rif, final int zoom)
	public StripesImageContainer(final MapScale img, JEditorPane editor,
			final ReqInternalFrame rif) {
		// super(new ImageIcon(img));
		super(new ImageIcon(img.getImage()));
		this.edit = editor;
		// Para posisionarse en el texto cuando se presiona en algun lugar de la
		// imagen
		img.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				// La multiplicacion es por el zoom que se aplica
				Point p = new Point(
						(int) ((e.getPoint().x * 3 / img.getScale())), (int) (e
								.getPoint().y * 3 / img.getScale()));
				/*
				 * if(img.getScale()==1) p = new
				 * Point((int)((e.getPoint().x*3)), (int)((e.getPoint().y*3)));
				 * else if(img.getScale()==2) p = new
				 * Point((int)((e.getPoint().x*3/img.getScale())),
				 * (int)(e.getPoint().y*3/img.getScale())); else
				 * if(img.getScale()==1.5) p = new
				 * Point((int)((e.getPoint().x*3)*0.5),
				 * (int)(e.getPoint().y*3*0.5)); else if(img.getScale()==2.0) p
				 * = new Point((int)((e.getPoint().x*3)/2),
				 * (int)(e.getPoint().y*3/2));
				 */

				// StripesImageContainer.this.edit.setCaretPosition(StripesImageContainer.this.edit.viewToModel(e.getPoint()));
				StripesImageContainer.this.edit
						.setCaretPosition(StripesImageContainer.this.edit
								.viewToModel(p));
				StripesImageContainer.this.edit.requestFocus();
				rif.radioTextActionPerformed(null);
				System.out.println("Se presiono en la imagen" + e.getPoint());
			}
		});
	}
}
